# 导入模块
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.feature as cfeat
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
from cartopy.mpl.ticker import LongitudeFormatter,LatitudeFormatter
import cartopy.io.shapereader as shpreader
import cartopy.io.img_tiles as cimgt
import numpy as np

import matplotlib.patches as patches

import cartopy.crs as ccrs
import matplotlib.pyplot as plt
import cartopy.io.img_tiles as cimgt
import matplotlib.ticker as mticker

from ppgnss import gnss_utils
width, height = gnss_utils.cm2inch(10), gnss_utils.cm2inch(8)
fig = plt.figure(figsize=(width, height))

ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())
plt.subplots_adjust(left=0.13, right=0.98, bottom=0.1, top=0.98)

ax.set_extent([120.4, 121.1, 29.99, 30.61],crs=ccrs.PlateCarree())
request = cimgt.TDT_img()
ax.add_image(request, 11)
gl = ax.gridlines(draw_labels=True, linewidth=0.5, color='white', alpha=1, linestyle='--')
gl.xlocator = mticker.FixedLocator(np.arange(120.5, 121.1, 0.25))
gl.ylocator = mticker.FixedLocator(np.arange(30.0, 30.7, 0.2))

gl.xlabels_top = gl.ylabels_right = False 
gl.xformatter = LONGITUDE_FORMATTER 
gl.yformatter = LATITUDE_FORMATTER
lat_min, lon_min = 30.2025, 120.7177
lat_max, lon_max = 30.2320, 120.75
# ax.plot([lon_min, lon_max, lon_max, lon_min, lon_min], [lat_max, lat_max, lat_min, lat_min, lat_max], c="r")

plt_img = "figures/map.png"
plt.savefig(plt_img, dpi=300)
plt.show()
